#include<bits/stdc++.h>
using namespace std;

struct node
{
    int val;
    node* next;
    node(int val):val(val),next(nullptr){};
};

node* fanz(node* head){
    node* cur = nullptr;
    while (head!=nullptr)
    {
        node* temp=head;
        node* temp_2=head->next;
        head->next = cur;
        cur = temp;
        head = temp_2;
        /* code */
    }
    return cur;
}

int main(int argc, char const *argv[])
{
    /* code */
    node* head=new node(1);
    node* next1=new node(2);
    node* next2=new node(3);
    node* next3=new node(4);
    head->next=next1;
    next1->next=next2;
    next2->next=next3;
    node* res = nullptr;
    res = fanz(head);
    while(res!=nullptr){
        cout<<res->val<<" ";
        res = res->next;
    }
    return 0;
}

